package ThreadPoolnio1;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class mulitreadGUI {
    private JPanel panel1;
    private JTextField txtHostName;
    private JTextField txtHostPort;
    private  TCPServer_Thread tcpServer_thread = null;

    public mulitreadGUI() {
        btnStart.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                NetPrintStream printStream=new NetPrintStream(System.out,txtResult);
                System.setErr(printStream);
                System.setOut(printStream);
//                tcpServer_thread = new TCPServer_Thread();
//                tcpServer_thread.start();
                NIOServer nioServer = new NIOServer();
                nioServer.start();
            }
        });

        btnStop.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if(tcpServer_thread != null){
               tcpServer_thread.stopThreadPool();
                tcpServer_thread.interrupt();
              }
            }
        });
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("mulitreadGUI");
        frame.setContentPane(new mulitreadGUI().panel1);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }

    private JTextArea txtResult;
    private JButton btnStart;
    private JButton 退出Button;
    private JButton btnStop;


}
/*
cd C:\Users\Administrator\IdeaProjects\project1\out\production\project1
java ThreadPool2.TCPClient2
 */